package models;

import models.admin.AdminUser;
import models.constants.DeletedStatus;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Created by liming on 16/7/16.
 */
@Entity
@Table(name = "admin_stock_init")
public class AdminStockInit extends BaseModel {
    /**
     * 库存初始化编号
     */
    @Column(name = "code")
    public String code;

    /**
     * 初始化仓库
     */
    @ManyToOne
    @JoinColumn(name = "admin_warehouse_id")
    public AdminWarehouse adminWarehouse;

    /**
     * 库存初始化总金额
     */
    @Column(name = "total_amount")
    public Double totalAmount=0D;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;

    /**
     * 删除状态
     */
    @Column(name = "deleted_status")
    public DeletedStatus deletedStatus;

    /**
     * 审核人
     */
    @ManyToOne
    @JoinColumn(name = "audit_user_id")
    public AdminUser auditUser;

    /**
     * 审核时间
     */
    @Column(name = "audit_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date auditDate;

    @Transient
    public  String createAtStr;

    @Transient
    public  String auditDateStr;

    /**
     * 版本号
     */
    @Version
    public Integer version;

    /**
     * 查询所有的初始化库存表
     */
    public static List<AdminStockInit> findAllAdminStockInit() {
        return AdminStockInit.find("deletedStatus=?", DeletedStatus.UN_DELETED).fetch();
    }

    /**
     * 根据ID查询初始化库存表
     */
    public static AdminStockInit findByStockInitId(Long id) {
        return AdminStockInit.find("id=? and deletedStatus=?", id, DeletedStatus.UN_DELETED).first();
    }


}
